//
// Created by DengLibin on 2018/12/8 0008.
//

#include <stdio.h>
#include <stdlib.h>
//内存分配

void consum()
{
    long long ll = 1024 * 1024 * 1024; // 1G内存
    char *p = (char *)calloc(ll, 1);   //一次分配很大内存
    if (p == NULL)
    {
        printf("内存分配失败\n");
        return;
    }
    printf("内存分配成功\n");
    //一直分配内存，每次分配100M
    while (1)
    {
        char *p1 = (char *)calloc(1024 * 1024 * 100, 1);
        if (p1 != NULL)
        {
            int j = 0;
            for (; j < 1024 * 1024 * 100; j++)
            {
                p1[j] = 'k';
            }
            printf("分配了100M内存\n");
        }
    }
}
int main3()
{
    consum();
    return 0;
}
